﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace LogNaga.Configuration
{
	//2009-12-1 范维肖 更改

	/// <summary>
	/// 日志记录配置节定义
	/// </summary>
	/// <remarks>配置Logging组件</remarks>
	public sealed class LoggingConfigurationSection : ConfigurationSection
	{
		private readonly string dir;

		/// <summary>
		/// 构造函数，初始化LogginConfigurationSection实例
		/// </summary>
		public LoggingConfigurationSection()
		{
		}

		/// <summary>
		/// 设置如果记录为文本的话设置目录名
		/// </summary>
		[ConfigurationProperty("directoryName", DefaultValue = "Site_Log", IsRequired = false)]
		public string DirectoryName
		{
			get
			{
				return string.Format("..\\{0}\\", this["directoryName"].ToString());
			}
		}

		/// <summary>
		/// 如果设置为使用db存储的话指定数据库连接字符串名称
		/// </summary>
		[ConfigurationProperty("connectionStringName", DefaultValue = "ErrorLogging", IsRequired = false)]
		public string ConnectionStringName
		{
			get
			{
				return this["connectionStringName"] as String;
			}
		}

		/// <summary>
		/// 获取配置
		/// </summary>
		/// <returns></returns>
		public static LoggingConfigurationSection GetConfig()
		{
			var section = ConfigurationManager.GetSection("logging");
			if (section == null)
				throw new ConfigurationErrorsException("logging");

			return section as LoggingConfigurationSection;
		}
	}
}
